package com.ai.imagetext.repository;

import com.ai.imagetext.entity.OperationLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OperationLogRepository extends JpaRepository<OperationLog, Integer> {

    /**
     * 查询用户最新的前十个操作日志
     */
    @Query("SELECT o FROM OperationLog o WHERE o.userId = :userId AND o.isDelete = false ORDER BY o.createTime DESC")
    List<OperationLog> findTop10ByUserIdAndIsDeleteFalseOrderByCreateTimeDesc(@Param("userId") Long userId);

    /**
     * 查询用户指定类型的最新前十个操作日志
     */
    @Query("SELECT o FROM OperationLog o WHERE o.userId = :userId AND o.type = :type AND o.isDelete = false ORDER BY o.createTime DESC")
    List<OperationLog> findTop10ByUserIdAndTypeAndIsDeleteFalseOrderByCreateTimeDesc(@Param("userId") Long userId, @Param("type") Integer type);

}
